package com.ldc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldc.model.SysRoleMenu;
import com.ldc.service.mapper.RoleMenuMapper;
import com.ldc.service.service.RoleMenuService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能说明
 *
 * @auther liudc
 * @since 2023/7/14
 */
@Service
public class RoleMenuImpl extends ServiceImpl<RoleMenuMapper, SysRoleMenu> implements RoleMenuService {

    @Override
    public List<SysRoleMenu> findListBy(LambdaQueryWrapper<SysRoleMenu> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public List<SysRoleMenu> findListByMenuId(long menuId) {
        return findListBy(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getMenuId, menuId));
    }

    @Override
    public List<SysRoleMenu> findListByMenuIds(List<Long> menuId) {
        return findListBy(new QueryWrapper<SysRoleMenu>().lambda().in(SysRoleMenu::getMenuId, menuId));
    }

    @Override
    public List<Long> getMenuIdsByRoleIds(List<Long> roleIdList) {
        return findListBy(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, roleIdList)).stream()
                .map(SysRoleMenu::getMenuId).collect(Collectors.toList());
    }

    @Override
    public SysRoleMenu findBy(LambdaQueryWrapper<SysRoleMenu> queryWrapper) {
        return getBaseMapper().selectOne(queryWrapper);
    }

    @Override
    public int batchDeleteBy(LambdaQueryWrapper<SysRoleMenu> queryWrapper) {
        return getBaseMapper().delete(queryWrapper);
    }

    @Override
    public int batchDeleteByMenuIds(List<Long> ids) {
        return batchDeleteBy(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getMenuId, ids));
    }
}
